#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
#include "PL6_worker.h"

using std::cout;
using std::endl;
using std::cin;
using std::srand;
using std::rand;
using std::string;
int main(int argc, char const *argv[])
{
    const int num=10;
    srand(std::time(0));
    int n;
    cout << "Enter stack size: ";
    cin >> n;

    Stack<string> stk(n);
    stk.show();

    const string in[num]={
        "1:a", "2:b", "3:c", "4:d", "5:e", "6:f", "7:g", "8:h", "9:i", "10:j"
    };
    string out[num];
    int nextin=0;
    int processed=0;
    bool flag=true;
    while (processed<num){
        // cout << "flag on processed "<<processed<<" : " ;
        if (stk.isempty())
            {
                flag = stk.push(in[nextin++]);
                cout <<"push flag:"<< flag << " and data:"<< in[nextin-1] << endl;
            }
        else if (stk.isfull())
            {
                flag = stk.pop(out[processed++]);
                cout <<"pop flag:"<< flag << " and data:"<< out[processed-1] << endl;
            }
        else if (rand() % 2 == 0 && nextin<num)
            {
                flag=stk.push(in[nextin++]);
                cout <<"push flag:"<< flag << " and data:"<< in[nextin-1] << endl;
            }
        else
            {
                flag=stk.pop(out[processed++]);
                cout <<"pop flag:"<< flag << " and data:"<< out[processed-1] << endl;
            }
        stk.show();
    }
    
    for (int i = 0; i < num; i++)
    {
        cout << out[i] << endl;
    }
    // stk.show();
    return 0;
}
